from PyQt5.QtWidgets import QMessageBox

from backEnd import utils
from backEnd.database.DBOperation import db_Operation


def get_account_by_id(id):
    db = db_Operation()
    re, df = db.selectAll("account")
    result = df[(df['id'] == int(id))]
    return result.values.tolist()


def do_fund_by_id(id, operation, do_number):
    db = db_Operation()
    re, df = db.selectAll("account")
    result = df[(df['id'] == int(id))]
    # 获取余额
    remaining = int(result.values.tolist()[0][4])
    # 进行存款取款操作
    if operation == "in":
        remaining += int(do_number)
    else:
        remaining -= int(do_number)
    re, exception = db.update("account", ["id"], [id], {"remaining": remaining})
    return re, exception


def get_history_by_id(id, name):
    db = db_Operation()
    re, df = db.selectAll("account_history")
    result = df[(df['id_operator'] == int(id)) & (df['name_operator'] == str(name))]

    return result.values.tolist()


get_history_by_id(1, "account")
